from django.db import models
from users.models import UserModel

# Create your models here.

class CouponModel(models.Model):
    coupon_type = (
        ('1','满减'),
    )
    status_type = (
        (0,'未启用'),
        (1,'启用'),
        (2,'已过期'),
    )
    name = models.CharField(max_length=50,verbose_name='优惠券名称')
    coupon_type = models.SmallIntegerField(choices=coupon_type,verbose_name='优惠券类型')
    start_time = models.DateTimeField(verbose_name='开始时间')
    end_time = models.DateTimeField(verbose_name='结束时间')
    condition = models.IntegerField(verbose_name='满足条件金额')
    reduction = models.IntegerField(verbose_name='减免金额')
    status = models.SmallIntegerField(choices=status_type,verbose_name='状态')
    create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')

    def __str__(self):
        return self.name


class UserCouponModel(models.Model):
    status_type = (
        (0,'未使用'),
        (1,'已使用'),
        (2,'已过期'),
    )
    user = models.ForeignKey(UserModel,on_delete=models.DO_NOTHING,db_constraint=False,related_name='ucoupon_user')
    coupon = models.ForeignKey(CouponModel,on_delete=models.DO_NOTHING,db_constraint=False,related_name='ucoupon_coupon')
    status = models.SmallIntegerField(choices=status_type,verbose_name='状态')
    create_time = models.DateTimeField(auto_now_add=True)


    def __str__(self):
        return self.user.username



